{extends file="../home.html"}
{block name="title"}{$head_title}{/block}
{block name="css"}
<!-- <link rel="stylesheet" style="text/css" href="__PUBLIC__/Css/front/user_glb.css?version={$version}"> -->

<style type="text/css">
    body{
    	padding-top:2.2rem;
    }
</style>
{/block}
{block name="content"}
<div class="service_header">
    <i class="icon icon_back_default3x mui-action-back" onclick="bpBack();" style="top:.7rem"></i>
    <span  onclick="bpBack();">返回</span>
    <p>提交BP</p>
</div>
<form id='form1'>
<ul class="visit_from">
    <li class="clearfix">
        <label for="name" class="fl">项目名称</label>
        <input type="text" id="name" name="project_name" value="" placeholder="请输入项目名称">
    </li>
    <li class="clearfix">
        <label for="invest-money" class="fl">融资金额</label>
        <input type="number" id="invest-money" name="financing_money" value="" placeholder="请输入融资金额">
    </li>
    <li class="clearfix">
        <label for="industry" class="fl">所属行业</label>
        <!-- <input type="text" id="industry" name="" value="" placeholder="请输入所属行业"> -->
        <select name="field" id="focus-lingyu">
            <option value=''>请选择所属领域</option>
            {foreach from=$field_list item=v}
            <option value='{$v.type_id}'>{$v.type_name}</option>
            {/foreach}
        </select>
    </li>
    <li class="clearfix">
        <label for="invest-stage" class="fl">投资阶段</label>
        <!-- <input type="text" id="invest-stage" name="" value="" placeholder="请输入投资阶段"> -->
        <select name="phase" id="focus-jieduan">
            <option value=''>请选择所属阶段</option>
            {foreach from=$phase_list item=v}
            <option value='{$v.type_id}'>{$v.type_name}</option>
            {/foreach}
        </select>
    </li>
</ul>
<h6 class="bei">项目说明</h6>
<textarea name="project_highlight" placeholder="请输入项目说明" class="bei_txt" style="box-sizing:border-box;" maxlength="20"></textarea>
<h6 class="bei">项目简介</h6>
<textarea name="project_desc" placeholder="请输入项目简介" class="bei_txt" style="box-sizing:border-box;"></textarea>
<h6 class="bei">封面图</h6>
<div class="up_img clearfix" style="margin:0;">
    <div class="preview-pic fl clearfix img_html">
        <div class="up_img_box fl">
            <a href="javascript:;" class="add icon fl icon_upload_default3x" title="上传一张新的图片" id="pic"></a>
            <!-- <input type="hidden" name="img_url_plan" class="img_url_plan" id="img_url_plan" /> -->
        </div>
        <input type="hidden" name='pic'>
    </div>
</div>
<h6 class="bei">上传商业计划书</h6>
<div class="up_img clearfix" style="margin:0;">
	<div class="preview-plan fl clearfix img_html">
        {if $is_ios == 0}
		<div class="up_img_box fl">
	        <a href="javascript:;" class="add icon fl icon_upload_default3x" title="上传商业计划书" id="upload-plan"></a>
	        <!-- <input type="hidden" name="img_url_plan" class="img_url_plan" id="img_url_plan" /> -->
	    </div>
        <input type="hidden" name='plan_book'>
        {else}
        请将商业计划书发送邮件至{$service_email}
        {/if}
	</div>
</div>

<h6 class="bei">上传自荐材料</h6>
<div class="up_img clearfix">
	<div class="preview-recom fl clearfix img_html">
        {if $is_ios == 0}
		<div class="up_img_box fl">
	        <a href="javascript:;" class="add icon fl icon_upload_default3x" title="上传一张新的图片" id="upload-recom"></a>
	        <!-- <input type="hidden" name="img_url_recom " class="img_url_recom" id="img_url_recom" /> -->
	    </div>
        <input type="hidden" name='cover'>
        {else}
        请将自荐材料发送邮件至{$service_email}
        {/if}
	</div>
</div>
<input type="hidden" name='is_ios' value="{$is_ios}">
<div class="submit_btn">提交</div>
</form>
{/block}
{block name="js"}

	<script type="text/javascript" src="/Public/Js/front/front_js/ajaxupload.3.5.js"></script>
	<script type="text/javascript">
	    var is_ios = parseInt('{$is_ios}');
        var is_click = false;
        {literal}
	        function ios(){
			    var browserName = navigator.userAgent.toLowerCase();
			    return /(iphone|ipod|ipad)/i.test(browserName);
			}
			function bpBack(){
        		var _json = JSON.stringify({
		            event: 'back'
		        });
        		if(!is_wechat()){
        			if (ios()) {
			            return window.webkit.messageHandlers.webviewEvent.postMessage(_json);
			        } else {
			            return ResultAndroid.webviewEvent(_json);
			        }
				}else{
					history.go(-1);
				}
        	}
	    $(".submit_btn").on("click",function(){
            if(is_click){
                return;
            }
            is_click = true;

	    	if($("#name").val()==''){
                layer.open({
                    content: '请输入项目名称',
                    title: false,
                    btn: ['确定'],
                });
                return;
            }
	    	/*if($("#invest-money").val()==''){
                layer.open({
                    content: '请输入融资金额',
                    title: false,
                    btn: ['确定'],
                });
                return;
            }*/
	    	if($("input[name=field]").val()==''){
                layer.open({
                    content: '请选择所属行业',
                    title: false,
                    btn: ['确定'],
                });
                return;
            }
	    	if($("input[name=phase]").val()==''){
                layer.open({
                    content: '请选择投资阶段',
                    title: false,
                    btn: ['确定'],
                });
                return;
            }
            if($("input[name=project_highlight]").val()==''){
                layer.open({
                    content: '请填写项目亮点',
                    title: false,
                    btn: ['确定'],
                });
                return;
            }
            if($("input[name=project_desc]").val()==''){
                layer.open({
                    content: '请填写项目简介',
                    title: false,
                    btn: ['确定'],
                });
                return;
            }
            if(is_ios == 0){


                if($("input[name=plan_book]").val()==''){
                    layer.open({
                        content: '请上传商业计划书',
                        title: false,
                        btn: ['确定'],
                    });
                    return;
                }
                if($("input[name=cover]").val()==''){
                    layer.open({
                        content: '请上传自荐材料',
                        title: false,
                        btn: ['确定'],
                    });
                    return;
                }
            }
            $.ajax({
                url:'/FrontEnjoy/add_bp',
                type:'post',
                data: $('#form1').serialize(),
                success:function(r){
                    if(r.code == 0){
                        //alert(r.msg);
                        layer.open({
                                content: r.msg,
                                title: false,
                                btn: ['确定'],
                                yes:function(){
                                    location.href='/FrontEnjoy/bp_list';
                                    //mui.back();
//                                history.go(-1);
                            }
                        });
                       // history.go(-1);
                        
                    }else{
                        layer.open({
                                content: r.msg,
                                title: false,
                                btn: ['确定'],
                            });
                        is_click = false;
                        return;
                    }
                }
            })

	    });
	    new AjaxUpload("#pic", {
            action: "/Front/uploadHandler",
            name: "upfile",
            responseType: "json",
            onSubmit: function(){
                //alert('正在上传');
                //preview处的图片改为loading图片
                /*$('.preview-plan').show();
                if($("#upload-plan").siblings('.preview-plan').find('img').length>=3){
                    alert("最多上传3张图片");
                    return false;
                }*/
            },
            onChange: function(file, extension){
                if (extension && /^(jpg|png|jpeg|gif)$/.test(extension)) {
                    return true;
                }
                else {
                    //alert('暂不支持该图片格式！');
                    layer.open({
                                content: '暂不支持该文件格式',
                                title: false,
                                btn: ['确定'],
                            });
                    return false;
                }
            },
            onComplete: function(file, response){
            //  console.log(response);
                if (response.status === 0) {
                    //alert(response.msg);
                }
                else if (response.status === 1) {
                    var html;
                    html='<div class=" fl img_box"><img class="pic-preview" src="'+response.img_url+'"/><div class="del_img"></div></div>';
                    $('.preview-pic').prepend(html);
                    // $("#add_upload").siblings('.preview').show();
                    //$("#img_url_plan").val(1);
                    //删除图片
                    $(".del_img").on("click",function(){
                        if($(this).parents(".preview-pic").find('img').length==1){
                            //$(this).parents(".img_html").siblings('.img_url_plan').val('');      
                        }
                        $(this).parent(".img_box").remove();
                        $('.preview-pic').find('.up_img_box').show();
                    });
                    $('input[name=pic]').val(response.img_url);
                    $('.preview-pic').find('.up_img_box').hide();
                }
            }
        });
	    // 上传图片
        new AjaxUpload("#upload-recom", {
            action: "/Front/uploadFileHandler",
            name: "upfile",
            responseType: "json",
            onSubmit: function(){
            	//alert('正在上传');
                //preview处的图片改为loading图片
                $('.preview-recom').show();
                /*if($("#upload-recom").siblings('.preview-recom').find('img').length>=3){
                    alert("最多上传3张图片");
                    return false;
                }*/
            },
            onChange: function(file, extension){
                if (extension && /^(doc|docx|pdf|xls|xlsx)$/.test(extension)) {
                    return true;
                }
                else {
                    //alert('暂不支持该文件格式！');
                    layer.open({
                                content: '暂不支持该文件格式',
                                title: false,
                                btn: ['确定'],
                            });
                    return false;
                }
            },
            onComplete: function(file, response){
            //  console.log(response);
                if (response.status === 0) {
                    //alert(response.msg);
                }
                else if (response.status === 1) {
                    console.log('success');
                    var html;
                    html='<div class=" fl img_box"><img class="pic-preview" src="/Public/Images/front/front_img/word.png" /><div class="del_img"></div></div>';
                    $('.preview-recom').prepend(html);
                    // $("#add_upload").siblings('.preview').show();
                    //$("#img_url_recom").val(1);
                    //删除图片
                    $(".del_img").on("click",function(){
		                if($(this).parents(".preview").find('img').length==1){
		                	console.log(1);
		                    $(this).parents(".img_html_recom").siblings('.img_url_recom').val('');      
		                }
		                $(this).parent(".img_box").remove();
                        $('.preview-recom').find('.up_img_box').show();
		            });

                    $('input[name=cover]').val(response.img_url);
                    $('.preview-recom').find('.up_img_box').hide();
                }
            }
        });
        new AjaxUpload("#upload-plan", {
            action: "/Front/uploadFileHandler",
            name: "upfile",
            responseType: "json",
            onSubmit: function(){
            	//alert('正在上传');
                //preview处的图片改为loading图片
                /*$('.preview-plan').show();
                if($("#upload-plan").siblings('.preview-plan').find('img').length>=3){
                    alert("最多上传3张图片");
                    return false;
                }*/
            },
            onChange: function(file, extension){
                if (extension && /^(doc|docx|pdf|xls|xlsx)$/.test(extension)) {
                    return true;
                }
                else {
                    layer.open({
                                content: '暂不支持该文件格式',
                                title: false,
                                btn: ['确定'],
                            });
                    return false;
                }
            },
            onComplete: function(file, response){
            //  console.log(response);
                if (response.status === 0) {
                    //alert(response.msg);
                }
                else if (response.status === 1) {
                    var html;
                    html='<div class=" fl img_box"><img class="pic-preview" src="/Public/Images/front/front_img/word.png" /><div class="del_img"></div></div>';
                    $('.preview-plan').prepend(html);
                    // $("#add_upload").siblings('.preview').show();
                    //$("#img_url_plan").val(1);
                    //删除图片
                    $(".del_img").on("click",function(){
		                if($(this).parents(".preview-plan").find('img').length==1){
		                    $(this).parents(".img_html").siblings('.img_url_plan').val('');      
		                }
		                $(this).parent(".img_box").remove();
                        $('.preview-plan').find('.up_img_box').show();
		            });
                    $('input[name=plan_book]').val(response.img_url);
                    $('.preview-plan').find('.up_img_box').hide();
                }
            }
        });
        

	</script>
{/literal}
{/block}